#! /bin/sh
patch -p1 -l -f $* < $0
exit $?

From 290479782278cdf07945be059eb47580fc8502ac Mon Sep 17 00:00:00 2001
From: Andre Heinecke <aheinecke@gnupg.org>
Date: Mon, 4 Mar 2019 10:22:23 +0100
Subject: [PATCH] Make binary icons cross compilable

This uses KF5_HOST_TOOLING as used by other frameworks
to find host libraries and builds qrcAlias as external
project against it.
---
 CMakeLists.txt                        | 28 +++++++++++++++++++++++----
 qrcAlias/CMakeLists.txt               |  8 ++++++++
 qrcAlias.cpp => qrcAlias/qrcAlias.cpp |  0
 3 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 qrcAlias/CMakeLists.txt
 rename qrcAlias.cpp => qrcAlias/qrcAlias.cpp (100%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1045e6b3..920a535a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,6 @@ include(GtkUpdateIconCache)
 # Dependencies
 set(REQUIRED_QT_VERSION 5.10.0)

-# When cross-compiling, we should compile qrcAlias natively (against a native Qt build)
 if (CMAKE_CROSSCOMPILING)
     set(BINARY_ICONS_RESOURCE_OPTION_DEFAULT OFF)
 else()
@@ -30,9 +29,30 @@ option(BINARY_ICONS_RESOURCE "Install Qt binary resource files containing breeze
 option(SKIP_INSTALL_ICONS "Skip installing the icons files" OFF)

 if(BINARY_ICONS_RESOURCE)
-    find_package(Qt5 NO_MODULE REQUIRED Core)
-    add_executable(qrcAlias qrcAlias.cpp)
-    target_link_libraries(qrcAlias PUBLIC Qt5::Core)
+    if (CMAKE_CROSSCOMPILING)
+        if (NOT KF5_HOST_TOOLING)
+            message(FATAL_ERROR "Please provide a prefix with a native Qt build and pass -DKF5_HOST_TOOLING=path or disable BINARY_ICONS_RESOURCE")
+        endif()
+
+        # search native tooling prefix
+        string(FIND ${KF5_HOST_TOOLING} /lib idx)
+        string(SUBSTRING ${KF5_HOST_TOOLING} 0 ${idx} NATIVE_PREFIX)
+        message(STATUS "Building qrcAlias against ${NATIVE_PREFIX}")
+
+        include(ExternalProject)
+        ExternalProject_Add(native_qrcAlias
+                            SOURCE_DIR ${CMAKE_SOURCE_DIR}/qrcAlias
+                            CMAKE_ARGS -DCMAKE_PREFIX_PATH=${NATIVE_PREFIX}
+                                -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
+                            INSTALL_COMMAND ""
+                           )
+        add_executable(qrcAlias IMPORTED GLOBAL)
+        add_dependencies(qrcAlias native_qrcAlias)
+        set_target_properties(qrcAlias PROPERTIES IMPORTED_LOCATION
+            ${CMAKE_BINARY_DIR}/native_qrcAlias-prefix/src/native_qrcAlias-build/qrcAlias)
+    else ()
+        add_subdirectory (qrcAlias)
+    endif()

 function(generate_binary_resource target outfile)
     set(RESOURCES_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}/res)
diff --git a/qrcAlias/CMakeLists.txt b/qrcAlias/CMakeLists.txt
new file mode 100644
index 00000000..4199f2fe
--- /dev/null
+++ b/qrcAlias/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.5)
+
+# This lives in a subdirectory to make it easy to switch
+# the toolchain for cross compile.
+
+find_package(Qt5 NO_MODULE REQUIRED Core)
+add_executable(qrcAlias qrcAlias.cpp)
+target_link_libraries(qrcAlias PUBLIC Qt5::Core)
diff --git a/qrcAlias.cpp b/qrcAlias/qrcAlias.cpp
similarity index 100%
rename from qrcAlias.cpp
rename to qrcAlias/qrcAlias.cpp
--
2.20.1
